/*
*私募管理人 toolbar
*ToolBar.js*/

import React,{Component} from 'react';
import {Select,DatePicker,Input,message} from 'antd';
import moment from 'moment';

const dateFormat = 'YYYY-MM-DD'
const Option = Select.Option;
const RangePicker = DatePicker.RangePicker;
//联系人下拉组件
const LinkNameSelect=({dispatch,tag,data})=>{
	const myProps={
		onChange:(v)=>{
			console.log('vvvv',v)
			dispatch({
				type:`${tag}/setState`,
				payload:{
					linkNameId:v
				}
			})
		},
		placeholder:"全部",
		style:{width:150}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={item.id} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}
//私募名称下拉组件
const PrivateNameInput=({data,dispatch,tag})=>{
	function handleChange(e){
		console.log('eeeeeeeee',e.target.value)
		const value = e.target.value;
		dispatch({
			type:`${tag}/setState`,
			payload:{
				privateName:value
			}
		})
	}
	
	return (
		// <Input onChange={handleChange} placeholder="请输入" style={{width:150}}/>
		<Input onChange={handleChange} placeholder="请输入" style={{width:206}}/>
	)
}

//产品下拉组件
const PrivatePdtSelect=({data,dispatch,tag})=>{
	const myProps={
		onChange:(v)=>{
			console.log('vvvv',v)
			dispatch({
				type:`${tag}/setState`,
				payload:{
					linkName:v
				}
			})
		},
		placeholder:"请输入",
		style:{width:150}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={`${item.value}`} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}

//所属管理人下拉组件
const PrivateMgSelect=({data,dispatch,tag})=>{
	const myProps={
		onChange:(v)=>{
			console.log('vvvv',v)
			dispatch({
				type:`${tag}/setState`,
				payload:{
					nameId:v
				}
			})
		},
		placeholder:"请输入",
		style:{width:150}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={`${item.value}`} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}

//查询比赛名称
const GameNameSelect=({data,dispatch,tag})=>{
	function handleChange(e){
		console.log('eeeeeeeee',e.target.value)
		const value = e.target.value;
		dispatch({
			type:`${tag}/setState`,
			payload:{
				'gameName':value
			}
		})
	}
	return (
		// <Input onChange={handleChange} placeholder="请输入" style={{width:150}}/>
		<Input onChange={handleChange} placeholder="请输入" style={{width:206}}/>
	)
}

const DateRangePicker=({dispatch,qbeginDate,qendDate,tag})=>{
	const myProps={
		onChange:(v)=> {
			if(v.length){
				dispatch({
					type: `${tag}/setState`,
					payload: {
						qbeginDate:v[0].format("YYYYMMDD"),
						qendDate:v[1].format("YYYYMMDD")
					}
				})
			}else{
				dispatch({
					type: `${tag}/setState`,
					payload: {
						qbeginDate:'',
						qendDate:''
					}
				})
			}
			
		},
		allowClear:"false",
		style:{width:130}
	}
	if(qbeginDate){
		myProps.defaultValue=[moment(qbeginDate), moment(qendDate)]
	}

	return (
		<RangePicker
			{...myProps}
			//style={{ width: 200 }}
			style={{ width: 206,marginRight:20 }}
		/>
	)
}

//选择私募管理人
const PrevateManagerSelect=({data,dispatch,tag,getPrivatePdt})=>{
	const myProps={
		onChange:(v)=>{
			console.log('vvvv',v)
			dispatch({
				type:'privateGame/setState',
				payload:{
					managerId:v,
					pdtIdArr:''
				}
			})
			dispatch({
				type:'privateGame/getPrivatePdt',
				payload:{
					companId:v
				}
			})
		},
		placeholder:"请选择",
		style:{width:300}
	}
	return (
		<div>
			<Select {...myProps}>
				{
					data.map((item,i)=><Option value={`${item.id}`} key={i}>{item.name}({item.departmentName})</Option>)
				}
			</Select>
		</div>
		
	)
}
//选择产品
const PrevatePdtSelect=({data,value,dispatch,tag,competitionId})=>{
	console.log('vvvvPrevatePdtSelect>>>',data,competitionId)
	
	const myProps={
		value:value,
		onChange:(v)=>{
			console.log('vvvv',v)
			dispatch({
				type:"privateGame/setState",
				payload:{
					pdtIdArr:v
				}
			})
			dispatch({
				type:"privateGame/getPdtdepartment",
				payload:{
					porductId:v,
					competitionId:competitionId
				}
			})
		},
		placeholder:"请输入",
		style:{width:150}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={`${item.productId}`} key={i}>{item.productName}</Option>)
			}
		</Select>
	)
}
//选择赛区
const ZoneSelect=({data,dispatch,tag})=>{
	const myProps={
		onChange:(v)=>{
			console.log('vvvv',v)
			dispatch({
				zoneArr:v
			})
		},
		placeholder:"请输入",
		mode:"multiple",
		style:{width:150}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={`${item.id}`} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}

//排名赛区选择
const DivisionSelect=({data,dispatch,tag})=>{
	const myProps={
		onChange:(v)=>{
			console.log('vvvv',v)
			data.map(i=>{
				if(v == i.name){
					dispatch({
						type:`${tag}/setState`,
						payload:{
							divisionId:i.id
						}
					})
				}else if(v == undefined){
					dispatch({
						type:`${tag}/setState`,
						payload:{
							divisionId:''
						}
					})
				}
			})
		},
		mode:"combobox",
		allowClear:true,
		placeholder:"请输入",
		style:{width:150}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={`${item.name}`} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}
const DateRangeChoice=({dispatch,beginDate,endDate,firstDate,lastDate,tag})=>{
	console.log('DateRangeChoice',beginDate,endDate,tag)

	const myProps={
		onChange:(v)=> {
			if(v.length){
				if (!moment(v[0]).isBefore(v[1])) {
			    message.warning('开始时间大于结束时间!');
			    dispatch({
						type: `${tag}/setState`,
						payload: {
							'RbeginDate':v[0].format("YYYYMMDD"),
							'RendDate':v[1].format("YYYYMMDD")
						}
					})
			  }else{
			  	dispatch({
						type: `${tag}/setState`,
						payload: {
							'RbeginDate':v[0].format("YYYYMMDD"),
							'RendDate':v[1].format("YYYYMMDD")
						}
					})
			  }
			}else{
				dispatch({
					type: `${tag}/setState`,
					payload: {
						'RbeginDate':'',
						'RendDate':''
					}
				})
			}
		},
		allowClear:"false",

		style:{width:130}
	}
	if(beginDate){
		myProps.defaultValue=[moment(beginDate), moment(endDate)]
	}

	return (
		<RangePicker
			{...myProps}
			style={{ width: 200 }}
			disabledDate={current => firstDate?((current < moment(firstDate)) || (current > moment(lastDate))):false}
		/>
	)
}
//分公司下拉选择
const BranchOfficeChoice=({dispatch,data,allData,value,tag})=>{
	console.log('BranchOfficeChoice',data,tag)
	const myProps={
		value,
		onChange:(v)=>{
			if(v){
				const Id=allData.find(item=>item.code==v).id
				console.log('vvvv',v)
				dispatch({
					type:`${tag}/setState`,
					payload:{
						'BOfficeCode':v,
						'BOfficeId':Id,
						'BDepartmentName':''
					}
				})
			}else{
				dispatch({
					type:`${tag}/setState`,
					payload:{
						'BOfficeCode':'',
						'BOfficeId':'',
						'BDepartmentName':''
					}
				})
			}
			
		},
		// mode:"combobox",
		allowClear:true,
		placeholder:"请选择分公司",
		style:{width:150}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={`${item.code}`} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}
//营业部下拉选择
const BDepartmentChoice=({dispatch,value,data,tag})=>{
	console.log('BDepartmentChoice',data,tag)
	const myProps={
		defaultValue:'',
		value,
		onChange:(v)=>{
			console.log('vvvv',v)
			if(v){
				dispatch({
					type:`${tag}/setState`,
					payload:{
						'BDepartmentName':v,
					}
				})
			}else{
				dispatch({
					type:`${tag}/setState`,
					payload:{
						'BDepartmentName':'',
					}
				})
			}
			
		},
		// mode:"combobox",
		allowClear:true,
		placeholder:"请选择营业部",
		style:{width:200}
	}
	return (
		<Select {...myProps}>
			{
				data.map((item,i)=><Option value={`${item.id}`} key={i}>{item.name}</Option>)
			}
		</Select>
	)
}
export {
	PrivateNameInput,
	LinkNameSelect,
	PrivatePdtSelect,
	PrivateMgSelect,
	GameNameSelect,
	DateRangePicker,
	ZoneSelect,
	PrevatePdtSelect,
	PrevateManagerSelect,
	DivisionSelect,
	DateRangeChoice,
	BranchOfficeChoice,
	BDepartmentChoice
}